Option Explicit On 

Imports System
Imports System.Xml
Imports System.Data
Imports System.Data.OleDb
Public Class Class_InvCarRentDataType
    Private VTableSpaceName As String = "InvCarRentDataType"
    Function Save_Edit_Data(ByVal StrConn As String, ByVal DataTypeID As String, ByVal DataTypeName As String, ByVal DataTypeDesc As String, ByVal OtDay As String, ByVal OtHoliday As String, ByVal CostDay As String, _
    ByVal CostHoliday As String, ByVal CostDriver As String, ByVal HumanNum As String, ByVal DataTypeStatus As String, ByVal TypeId As String, _
    ByVal CarRentCostDay As String, ByVal CarRentCostHoliday As String, ByVal CarRentOTDay As String, ByVal CarRentOTHoliday As String, ByVal CarRentCostDriver As String) As Boolean
        Dim StrSql As String = ""
        Dim Conn As New OleDb.OleDbConnection
        Dim Cls As New Class_Connection
        Dim VTran As OleDb.OleDbTransaction

        StrSql = StrSql & " Delete InvCarDataType Where (DataTypeID = " & DataTypeID & "); " & vbCrLf

        StrSql = StrSql & " Insert Into InvCarDataType(DataTypeID,DataTypeName,DataTypeDesc,OtDay,OtHoliday," & vbCrLf
        StrSql = StrSql & " CostDay,CostHoliday,CostDriver,HumanNum,DataTypeStatus,TypeId,CarRentCostDay,CarRentCostHoliday," & vbCrLf
        StrSql = StrSql & " CarRentOTDay,CarRentOTHoliday,CarRentCostDriver ) " & vbCrLf
        StrSql = StrSql & "  Values (" & vbCrLf
        StrSql = StrSql & " " & DataTypeID & ","
        StrSql = StrSql & " '" & DataTypeName & "',"
        StrSql = StrSql & " '" & DataTypeDesc & "',"
        StrSql = StrSql & " " & OtDay & ","
        StrSql = StrSql & " " & OtHoliday & ","
        StrSql = StrSql & " " & CostDay & ","
        StrSql = StrSql & " " & CostHoliday & ","
        StrSql = StrSql & " " & CostDriver & ","
        StrSql = StrSql & " " & HumanNum & ","
        StrSql = StrSql & " " & DataTypeStatus & ","
        StrSql = StrSql & " " & TypeId & ","
        StrSql = StrSql & " " & CarRentCostDay & ","
        StrSql = StrSql & " " & CarRentCostHoliday & ","
        StrSql = StrSql & " " & CarRentOTDay & ","
        StrSql = StrSql & " " & CarRentOTHoliday & ","
        StrSql = StrSql & " " & CarRentCostDriver & ");"


        Conn = Cls.ConnectionOpen(StrConn)
        VTran = Cls.BeginTran(Conn)
        If Cls.ExecSql(Conn, StrSql, VTran) = True Then
            Cls.CommitTran(VTran)
            Save_Edit_Data = True
        Else
            Cls.RollBackTran(VTran)
            Save_Edit_Data = False
        End If
        Cls.ConnectionClose(Conn)

    End Function

    Function SelectData(ByRef StrConn As String, ByVal CarTypeID As String, ByVal CarTypeName As String, ByVal CarTypeStatus As String, Optional ByVal TableName As String = "") As DataSet
        Dim StrSql As String = ""
        Dim DA1 As OleDb.OleDbDataAdapter
        Dim DS1 As New DataSet
        Dim Conn As New OleDb.OleDbConnection
        Dim StrCondition As String = ""
        Dim Cls As New Class_Connection
        If (TableName = "") Then
            TableName = VTableSpaceName
        End If

        StrSql = StrSql & " Select * from InvCarDataType"

        If CarTypeID & "" <> "" Then
            If StrCondition & "" <> "" Then
                StrCondition = StrCondition & " And "
            End If
            StrCondition = StrCondition & "(DataTypeID = " & CarTypeID & ")"
        End If

        If CarTypeName & "" <> "" Then
            If StrCondition & "" <> "" Then
                StrCondition = StrCondition & " And "
            End If
            StrCondition &= "(DataTypeName like '%" & CarTypeName & "%')"
        End If

        If CarTypeStatus & "" <> "" Then
            If StrCondition & "" <> "" Then
                StrCondition = StrCondition & " And "
            End If
            StrCondition = StrCondition & "(DataTypeStatus like '%" & CarTypeStatus & "%')"
        End If


        If StrCondition & "" <> "" Then
            StrSql = StrSql & " Where "
            StrSql = StrSql & StrCondition
        End If

        StrSql = StrSql & " Order By TypeId,DataTypeName"


        Try
            Conn = Cls.ConnectionOpen(StrConn)
            DA1 = New OleDb.OleDbDataAdapter(StrSql, Conn)
            DA1.Fill(DS1, TableName)
            If (DS1.Tables(TableName).Rows.Count > 0) Then
                SelectData = DS1
            End If

        Catch ex As Exception
            SelectData = Nothing
        End Try

        Cls.ConnectionClose(Conn)
        DA1 = Nothing
        DS1 = Nothing
    End Function

End Class
